import {observable, action, toJS} from "mobx";
import {WeaLocaleProvider, WeaTools} from "ecCom";
import * as conLockApi from '../apis/contractLockSend';
import {Modal} from 'antd';
import "../style/index"

const getLabel = WeaLocaleProvider.getLabel;

class CusIntFac {
    @observable tabledata = [];
    @action updateTableData = (datas = []) => {
        this.tabledata = datas;
    }

    /**
     * 数据初始化 执行相关方法
     * @param params
     */
    init = (params) => {
        this.setLoading(true);
        params && params.workflowid && conLockApi && conLockApi.getInterfaceSeted(params).then(result => {
            this.setLoading(false);
            if (result.status = 1) {
                this.updateTableData(toJS(result.tabledatas));//可以用url区别
            } else {
                Modal.error({
                    title: getLabel(15172, "系统提示"),
                    content: result.msg || getLabel(126400, "获取数据失败!"),
                })
            }
        });
    }

    /**
     * 做数据保存操作
     * @param params 上传参数
     * @param cllbackfn 回调函数
     */
    @action
    doSaveInterfaceSetting = (params, cllbackfn) => {
        //数据验证
        if (params && params.workflowid && params.tabledatas) { //数据验证成功
            this.setLoading(true);
            conLockApi.doSaveInterfaceSetting(params).then(result => {//调用数据接口实现相关功能
                this.setLoading(false);
                if (result.status = 1) {
                    Modal.success({
                        title: getLabel(15172, "系统提示"),
                        content: getLabel(18758, "保存成功!"),
                        onOk() {
                            cllbackfn && cllbackfn();
                        },
                    });
                } else {
                    Modal.error({
                        title: getLabel(15172, "系统提示"),
                        content: result.msg || getLabel(84544, "保存失败!"),
                    })
                }
            })
        } else {//数据验证失败 提示
            Modal.error({
                title: getLabel(15172, "系统提示"),
                content: getLabel(385021, "数据为空!"),
            })
        }
    }

    @observable loading = true;
    @action("重新设置loading的值") setLoading = (ok = false) => {
        this.loading = ok;
    }
}

export {CusIntFac}